from manger import db
from marshmallow import Schema, fields, post_load

class SeletedStock(db.Model):
    __tablename__ = 'selected_stocks'
    id = db.Column(db.Integer, primary_key=True)
    CostLine15 = db.Column(db.Float, nullable=False)
    CostLine30 = db.Column(db.Float, nullable=False)
    Long = db.Column(db.String, nullable=False)
    Status = db.Column(db.Integer, nullable=False)
    Topics = db.Column(db.String, nullable=False)
    code = db.Column(db.String, nullable=False)
    ctime = db.Column(db.Integer, nullable=False)
    date = db.Column(db.DateTime, nullable=False)
    intro = db.Column(db.String, nullable=False)
    name = db.Column(db.String, nullable=False)
    score = db.Column(db.Float, nullable=False)
    snapshot = db.Column(db.String, nullable=False)
    tag = db.Column(db.String, nullable=False)
    utime = db.Column(db.Integer, nullable=False)
    kplTopics = db.Column(db.String, nullable=False)
    TopicsHot = db.Column(db.String, nullable=False)


    # def __repr__(self):
    #     return '<SeletedStock %r>' % self.name

class SeletedStockSchema(Schema):
    CostLine15 = fields.Float()
    CostLine30 = fields.Float()
    Long = fields.String()
    Status = fields.Integer()
    Topics = fields.String()
    code = fields.String()
    ctime = fields.Integer()
    date = fields.DateTime()
    id = fields.Integer()
    intro = fields.String()
    name = fields.String()
    score = fields.Float()
    snapshot = fields.String()
    tag = fields.String()
    utime = fields.Integer()
    kplTopics = fields.String()
    TopicsHot = fields.String()


    @post_load  # 反序列化成一个对象，给schema的一个方法加上post_load装饰器
    def post_load(self, data, **kwargs):
        return SeletedStock(**data)